package com.androturka;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;

public class Settings extends Activity {

	//Parametres
	public boolean workAtBackground;
	public int     workingFrequency;
	public boolean vibrationNotification;
	public boolean ringNotification;
		
	private Button    filtreleriAyarlaButton;

	private ConfigurationManager configurationManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);

		configurationManager = new ConfigurationManager(getApplicationContext());
		workAtBackground = configurationManager.getWorkAtBackGround();
		workingFrequency = configurationManager.getWorkingFrequency();
		vibrationNotification = configurationManager.getVibrationNofitication();
		ringNotification = configurationManager.getRingNotification();
					
		final CheckBox titresimIleUyariCheckbox = (CheckBox) findViewById(R.id.titresimIleUyariCheckbox);
		titresimIleUyariCheckbox.setChecked(vibrationNotification);
		titresimIleUyariCheckbox.setOnClickListener(new OnClickListener() {
		    @Override
			public void onClick(View v) {
		        if (((CheckBox) v).isChecked()) {
		        	vibrationNotification = true;
		        } else {
		        	vibrationNotification = false;
		        }
		        configurationManager.updateVibrationNotification(vibrationNotification);
		    }
		});

		final CheckBox kisaZilIleUyariCheckbox = (CheckBox) findViewById(R.id.kisaZilIleUyariCheckbox);
		kisaZilIleUyariCheckbox.setChecked(ringNotification);
		kisaZilIleUyariCheckbox.setOnClickListener(new OnClickListener() {
		    @Override
			public void onClick(View v) {
		        if (((CheckBox) v).isChecked()) {
		        	ringNotification = true;
		        } else {
		        	ringNotification = false;
		        }
		        configurationManager.updateRingNotificaiton(ringNotification);
		    }
		});
		
		filtreleriAyarlaButton = (Button)findViewById(R.id.filtreleriAyarlaButton);
		filtreleriAyarlaButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent filtreleriAyarlaIntent = new Intent(getApplicationContext(), FiltersActivity.class);
				startActivity(filtreleriAyarlaIntent);
			}
		});
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		
		if (configurationManager != null)
			configurationManager.cleanup();
	}
	
}
